﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Taurus.Platform.XML;

namespace Taurus.Platform.DTO
{
    /// <summary>
    /// 2009年12月28日
    /// 用户账号（将原先的friend与account类合并）
    /// </summary>
    public class UserAccount
    {
        private IPersistence<UserAccount> _per;

        public UserAccount()
        {
            SmallAccount = new List<string>();
            Friends = new List<string>();
            Groups = new List<string>();
            IsPublic = false;
            _per = new UserAccountPersistence();
        }

        /// <summary>
        /// 用户ID
        /// </summary>
        public string UID { get; set; }
        /// <summary>
        /// 用户名
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 邮件地址
        /// </summary>
        public string Email { get; set; }
        /// <summary>
        /// 密码
        /// </summary>
        public string Password { get; set; }
        /// <summary>
        /// 小号
        /// </summary>
        public List<string> SmallAccount { get; set; }
        /// <summary>
        /// 将小号ID包装成实体类
        /// </summary>
        public List<UserAccount> WrapperSmallAccount
        {
            get
            {
                List<UserAccount> list = new List<UserAccount>();
                foreach (var uid in SmallAccount)
                {
                    list.Add(_per.GetObject(uid));
                }
                return list;
            }
        }
        /// <summary>
        /// 好友列表
        /// </summary>
        public List<string> Friends { get; set; }
        /// <summary>
        /// 从页面获取的好友总数
        /// </summary>
        public int FriendsCount { get; set; }
        /// <summary>
        /// 将好友ID包装成实体类
        /// </summary>
        public List<UserAccount> WrapperFriends
        {
            get
            {
                List<UserAccount> list = new List<UserAccount>();
                foreach (var uid in Friends)
                {
                    list.Add(_per.GetObject(uid));
                }
                return list;
            }
        }
        /// <summary>
        /// 是否公共账号
        /// </summary>
        public bool IsPublic { get; set; }        
        /// <summary>
        /// 好友所属组
        /// </summary>
        public List<string> Groups { get; set; }
        /// <summary>
        /// 签名
        /// </summary>
        public string Signature { get; set; }
        /// <summary>
        /// 头像url全路径
        /// </summary>
        public string PicFullName { get; set; }
        /// <summary>
        /// 头像
        /// </summary>
        public string HeadImage
        {
            get
            {
                if (PicFullName!=string.Empty)
                {
                    Uri uri = new Uri(PicFullName);
                    return uri.Segments[uri.Segments.Length - 1];
                }
                else
                {
                    return string.Empty;
                }
                
            }
        }
    }
}
